package com.teachoa.bean;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.collections.CollectionUtils;

import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Page;
import com.teachoa.constant.Global;

public class Uncertain extends Model<Uncertain> {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6463849640386471368L;

	public static final Uncertain dao = new Uncertain();
	
	public Page<Uncertain> getUncertainPageByTeacherId(int pageNo, String userId) {
		return dao.paginate(pageNo, Global.pageSize, "select * ", "from uncertain where user_id = ? order by create_time desc", userId);
	}
	
	public Page<Uncertain> getUncertainPageByStudentId(int pageNo, String userId) {
		List<TeacherStudent> list = TeacherStudent.dao.getRelationBySid(userId);
		if(CollectionUtils.isEmpty(list))
			return null;
		String suffix = "from uncertain where user_id in (";
		List<String> teacherIds = new ArrayList<String>();
		for(int i=0;i<list.size();i++) {
			TeacherStudent ts = list.get(i);
			String teacherId = ts.getStr("teacher_id");
			if(i==list.size()-1)
				suffix +="?";
			else
				suffix += "?,";
			teacherIds.add(teacherId);
		}
		suffix += ") order by create_time desc";
		return dao.paginate(pageNo, Global.pageSize, "select * ", suffix, teacherIds.toArray());
	}
	
}
